package com.shop.service.impl;

import com.shop.bean.Category;

import com.shop.dao.CategoryDao;
import com.shop.service.ICategoryService;
import com.shop.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements ICategoryService {

    @Autowired
    CategoryDao categoryDao;


    @Override
    public int addCategory(Category category) {
        int lastlevel = category.getParent_id();
        if (lastlevel==-1){
            category.setLevel(1);
        }else {
            category.setLevel(2);
        }
        return categoryDao.addCategory(category);
    }

    @Override
    public int deleteCategory(int id) {
        return categoryDao.deleteCategory(id);
    }

    @Override
    public int editCategory(Category category) {
        int lastlevel = category.getParent_id();
        if (lastlevel==-1){
            category.setLevel(1);
        }else {
            category.setLevel(2);
        }
        return categoryDao.editCategory(category);
    }

    @Override
    public Category getCategoryById(int id) {
        return categoryDao.getCategoryById(id);
    }

    @Override
    public List<Category> selectCategories(Page page, String text) {
        return categoryDao.selectCategories(page, text);
    }

    @Override
    public List<Category> getChildren(int id) {
        return categoryDao.getChildren(id);
    }

    @Override
    public int getCount(String text) {
        return categoryDao.getCount(text);
    }
}

